package org.budo.ip.location.service.symphony;

import java.util.List;

import org.budo.ip.location.service.api.BudoIpLocation;
import org.budo.ip.location.service.api.BudoIpLocationService;
import org.budo.support.lang.util.ListUtil;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Getter
@Setter
@Slf4j
public class SymphonyIpLocationService implements BudoIpLocationService {
    private List<BudoIpLocationService> ipLocationServices;

    @Override
    public BudoIpLocation seekIpLocation(String ip) {
        if (ListUtil.isNullOrEmpty(this.getIpLocationServices())) {
            log.warn("#24 return null, ipLocationServices is null, phoneLocationServices=" + this.getIpLocationServices() + ", this=" + this);
            return null;
        }

        for (BudoIpLocationService budoPhoneLocationService : this.getIpLocationServices()) {
            BudoIpLocation ipLocation = budoPhoneLocationService.seekIpLocation(ip);
            if (null != ipLocation) {
                return ipLocation;
            }
        }

        log.warn("#24 return null, phoneLocationServices=" + this.getIpLocationServices() + ", this=" + this);
        return null;
    }
}